﻿<div class="page-header">
    <div class="row">
        <div class="col-md-8">
            <h2>{{::vm.translate.get('Users')}}</h2>
        </div>
        <div class="col-md-4 text-right">
            <a ui-sref="user-create" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> {{::vm.translate.get('Create User')}}</a>
        </div>
    </div>
</div>

<table class="table table-striped" st-pipe="vm.getUsers" st-table="vm.users">
    <thead>
        <tr>
            <th st-sort="Email" class="sortable">{{::vm.translate.get('Email')}}</th>
            <th st-sort="FullName" class="sortable">{{::vm.translate.get('FullName')}}</th>
            <th>{{::vm.translate.get('Roles')}}</th>
            <th>{{::vm.translate.get('Customer Groups')}}</th>
            <th st-sort="CreatedOn" class="sortable">{{::vm.translate.get('Created On')}}</th>
            <th>{{::vm.translate.get('Actions')}}</th>
        </tr>
        <tr>
            <th>
                <div class="form-group">
                    <input class="form-control" st-search="Email"/>
                </div>
            </th>
            <th>
                <div class="form-group">
                    <input class="form-control" st-search="FullName"/>
                </div>
            </th>
            <th>
                <div class="form-group">
                    <select class="form-control" st-search="RoleId">
                        <option value="">{{::vm.translate.get('All')}}</option>
                        <option ng-repeat="role in vm.roles" value="{{role.id}}">{{role.name}}</option>
                    </select>
                </div>
            </th>
            <th>
                <div class="form-group">
                    <select class="form-control" st-search="CustomerGroupId">
                        <option value="">{{::vm.translate.get('All')}}</option>
                        <option ng-repeat="group in vm.customerGroups" value="{{group.id}}">{{group.name}}</option>
                    </select>
                </div>
            </th>
            <th><st-date-range predicate="CreatedOn" before="query.before" after="query.after"></st-date-range></th>
            <th></th>
        </tr>
        <tr>
            <th ng-show="!vm.isLoading" colspan="6">{{vm.tableStateRef.pagination.totalItemCount | number:0}} records found</th>
        </tr>
    </thead>
    <tbody ng-show="!vm.isLoading">
        <tr ng-repeat="user in vm.users">
            <td>{{user.email}}</td>
            <td>{{user.fullName}}</td>
            <td>{{user.roles.join(', ')}}</td>
            <td>{{user.customerGroups.join(', ')}}</td>
            <td>{{user.createdOn | date:'medium' }}</td>
            <td>
                <a ui-sref="user-edit({id: user.id})" title="Edit" class="btn btn-primary btn-xs"> <span class="glyphicon glyphicon-pencil"></span></a>
                <button ng-click="vm.deleteUser(user)" class="btn btn-danger btn-xs delete"> <span class="glyphicon glyphicon-remove"></span></button>
            </td>
        </tr>
    </tbody>
    <tbody ng-show="vm.isLoading">
        <tr>
            <td colspan="6" class="text-center">Loading ... </td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td class="text-center" st-pagination="" st-items-by-page="50" st-displayed-pages="10" colspan="6"></td>
        </tr>
    </tfoot>
</table>	